package center.leon.zoonacos.controller;

import center.leon.zoocommon.holder.DynamicValueHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @author : Leon on XXM Mac
 * @since : create in 2024/8/14 10:17
 */
@Slf4j
@RestController
@RequestMapping("/hello")
public class HelloController {

    @Resource
    private DynamicValueHolder dynamicValueHolder;

    @PostMapping("/world")
    public String helloWorld() {
        return "Hello World!";
    }

    @PostMapping("/dynamic")
    public String helloDynamic() throws InterruptedException {
        for(int i = 0; i < 50;i++){
            log.info("dynamic : {}", dynamicValueHolder.getValue());
            TimeUnit.SECONDS.sleep(1);
        }
        return dynamicValueHolder.getValue();
    }
}
